<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%--
  Created by IntelliJ IDEA.
  User: 86132
  Date: 2020/10/23
  Time: 11:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>旅游宝 | 产品列表</title>
    <!-- Tell the browser to be responsive to screen width -->
    <jsp:include page="../include/header.jsp"></jsp:include>
</head>
<body class="hold-transition sidebar-mini">
<%--整个页面 div--%>
<div class="wrapper">
    <!-- Navbar  头部导航栏 -->
    <jsp:include page="../include/nav.jsp"></jsp:include>
    <!-- /.navbar -->

    <!-- Main Sidebar Container  侧边栏 左侧边栏 -->
    <jsp:include page="../include/left.jsp"></jsp:include>

    <!-- Content Wrapper. Contains page content  中部内容区   -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>产品管理</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">首页</a></li>
                            <li class="breadcrumb-item active">产品管理</li>
                        </ol>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <button style="width: 100px; float: right ;" type="button" onclick="toAdd()" class="btn btn-block btn-success">添加产品</button>
                                <form action="/goods/list" method="get" class="form-inline ml-3">
                                    <div class="input-group input-group-sm">
                                        <input value="${myParams.keywords}" name="keywords"
                                               class="form-control form-control-navbar" type="search" placeholder="搜索"
                                               aria-label="Search">
                                        <div class="input-group-append">
                                            <button class="btn btn-navbar" type="submit">
                                                <i class="fas fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <!-- /.card-header -->
                            <div class="card-body">
                                <table id="example2" class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>id</th>
                                        <th>产品名</th>
                                        <th>开始日期</th>
                                        <th>结束日期</th>
                                        <th>出行方式</th>
                                        <th>定价</th>
                                        <th>最大人数</th>
                                        <th>库存</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${goodsList}" var="goods">
                                        <tr>
                                            <td>${goods.id}</td>
                                            <td>${goods.name}</td>
                                            <td><fmt:formatDate type="date" value="${goods.startDate}"
                                                                pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                            <td><fmt:formatDate type="date" value="${goods.endDate}"
                                                                pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                            <td>${goods.outType}</td>
                                            <td>${goods.money}</td>
                                            <td>${goods.maxNum}</td>
                                            <td>${goods.storeNum}</td>
                                            <td><a href="/goods/toEdit?id=${goods.id}" class="btn btn-danger btn-sm">修改</a><a href="/goods/del?id=${goods.id}" class="btn btn-danger btn-sm">删除</a></td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                    <tfoot>

                                    </tfoot>
                                </table>
                                <div class="row">
                                    <div class="col-sm-12 col-md-5">
                                    </div>
                                    <div class="col-sm-12 col-md-7">
                                        <div class="dataTables_paginate paging_simple_numbers" id="example2_paginate">
                                            <c:if test="${myParams.totalPage>0}">
                                                <ul class="pagination">
                                                <c:if test="${myParams.page eq 1}">
                                                    <li class="paginate_button page-item previous disabled"
                                                        id="example2_previous">
                                                        <a href="javascript:jump('${myParams.page-1}');"
                                                           aria-controls="example2" data-dt-idx="0" tabindex="0"
                                                           class="page-link">上一页</a>
                                                    </li>
                                                </c:if>
                                                <c:if test="${myParams.page ne 1}">
                                                    <li class="paginate_button page-item previous "
                                                        id="example2_previous">
                                                        <a href="javascript:jump('${myParams.page-1}');"
                                                           aria-controls="example2" data-dt-idx="0" tabindex="0"
                                                           class="page-link">上一页</a>
                                                    </li>
                                                </c:if>

                                                <c:forEach begin="0" end="${myParams.totalPage-1}" varStatus="ind">
                                                    <c:if test="${myParams.page eq ind.index+1}">
                                                        <li class="paginate_button page-item active">
                                                            <a href="javascript:jump('${ind.index+1}');"
                                                               aria-controls="example2" data-dt-idx="1"
                                                               tabindex="0"
                                                               class="page-link">${ind.index+1}</a>
                                                        </li>
                                                    </c:if>
                                                    <c:if test="${myParams.page ne ind.index+1}">
                                                        <li class="paginate_button page-item ">
                                                            <a href="javascript:jump('${ind.index+1}');"
                                                               aria-controls="example2" data-dt-idx="1"
                                                               tabindex="0"
                                                               class="page-link">${ind.index+1}</a>
                                                        </li>
                                                    </c:if>
                                                </c:forEach>

                                                <c:if test="${myParams.page eq myParams.totalPage}">
                                                    <li class="paginate_button page-item next disabled"
                                                        id="example2_next">
                                                        <a href="javascript:jump('${myParams.page+1}');"
                                                           aria-controls="example2" data-dt-idx="7" tabindex="0"
                                                           class="page-link">下一页</a>
                                                    </li>
                                                </c:if>
                                                <c:if test="${myParams.page ne myParams.totalPage}">
                                                    <li class="paginate_button page-item next" id="example2_next">
                                                        <a href="javascript:jump('${myParams.page+1}');"
                                                           aria-controls="example2" data-dt-idx="7" tabindex="0"
                                                           class="page-link">下一页</a>
                                                    </li>
                                                </c:if>
                                            </ul>
                                            </c:if>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /.card-body -->
                        </div>
                        <!-- /.card -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper  页面 下面的 页脚-->
    <jsp:include page="../include/footer.jsp"></jsp:include>
    <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables -->
<script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<!-- AdminLTE App -->
<script src="../../js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../js/demo.js"></script>
<!-- page script -->
<script>
    $(function () {
        $('#example2').DataTable({
            "paging": false,
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "responsive": true,
        });
    });

    //连续跳转方法
    function jump(page) {
        var keywords = $("[name='keywords']").val();
        location.href = "/goods/list?page=" + page + "&keywords=" + keywords;
    }

    //添加页面
    function toAdd() {
        location.href = "/goods/toAdd";

    }
</script>
</body>
</html>

